<!DOCTYPE html>
<html lang="zh-CN" xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<head th:include="/common/inc::header"/>
<body>
<form class="layui-form" style="margin-top: 15px">
    <div class="layui-form-item">
        <label class="layui-form-label" style="width: 50px">账号:</label>
        <div class="layui-input-inline">
            <input type="text" name="account" id="account" autocomplete="off"
                   class="layui-input">
        </div>
        <label class="layui-form-label" style="width: 40px">姓名:</label>
        <div class="layui-input-inline">
            <input type="text" name="username" id="username" autocomplete="off"
                   class="layui-input">
        </div>
        <button class="layui-btn" id="searchBtn" lay-submit lay-filter="searchBtn" style="margin-left:50px">查询</button>
        <button class="layui-btn" lay-submit lay-filter="addBtn">新增地推人员</button>
    </div>
</form>
<table class="layui-table" id="grid" lay-filter="grid">
</table>
<script th:replace="/common/inc::incJs"></script>
<script>
    var tableIns;

    $(function () {
        tableIns = createTable({
            url: 'list',
            initSort: {
                field: 'createTime' //排序字段，对应 cols 设定的各字段名
                , type: 'desc' //排序方式  asc: 升序、desc: 降序、null: 默认排序
            },
            cols: [[
                {field: 'username', title: '姓名', width: 150}
                , {field: 'account', title: '账号', width: 150}, {
                    field: 'area',
                    title: '地区',
                    width: 100
                }, {
                    field: 'idCard',
                    title: '身份证',
                    width: 250
                }, {
                    field: 'bankNo',
                    title: '银行卡',
                    width: 250
                }, {field: 'status', title: '启用状态', width: 100, templet: '#statusTpl'},{field: 'applyStatus', title: '审核状态', width: 100, templet: '#applyStatusTpl'},  {
                    field: 'createTime',
                    title: '创建时间',
                    width: 150
                }, {
                    fixed: 'right',
                    title: '操作',
                    width: 400,
                    align: 'center',
                    toolbar: '#opbar'
                }
            ]], limit: 100
        });

        layui.table.on('tool(grid)', function (obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值
            var tr = obj.tr; //获得当前行 tr 的DOM对象
            if (layEvent === 'edit') { //编辑
                openDialog({
                    url: "/backend/security/bdTeam/detail?id=" + data.id,
                    area: ["70%", "90%"]
                });
            } else if (layEvent === 'change') { //删除
                changeStatus(data.id, data.status);
            } else if (layEvent === 'changeApply') { //删除
                changeApply(data.id, data.applyStatus);
            } else if (layEvent === 'codeForm') {
                openDialog({
                    url: "/backend/security/bdTeam/codeForm?bdTeamId=" + data.id + "&username=" + data.username,
                    area: ["80%", "95%"],
                    title: ['' + data.username + '', 'color: #FF0000;'],
                    btn: ""
                });

            }
        });
    });

    function changeStatus(id, status) {
        if (status == 0) {
            $.post('/backend/security/bdTeam/update', {id: id, status: 1}, function (res) {
                    if (res.code < 0) {
                        layer.msg(res.message);
                    }
                    else {
                        layer.msg("禁用成功");
                        tableIns.reload();
                    }
                }
            )
        } else if (status = 1) {
            $.post('/backend/security/bdTeam/update', {id: id, status: 0,applyStatus: 0}, function (res) {
                    if (res.code < 0) {
                        layer.msg(res.message);
                    }
                    else {
                        layer.msg("启用成功");
                        tableIns.reload();
                    }
                }
            )
        }
    }

    function changeApply(id, applyStatus) {
        if (applyStatus == 0) {
            $.post('/backend/security/bdTeam/update', {id: id, applyStatus: 1,status:1}, function (res) {
                    if (res.code < 0) {
                        layer.msg(res.message);
                    }
                    else {
                        layer.msg("审核不通过");
                        tableIns.reload();
                    }
                }
            )
        } else if (applyStatus = 1) {
            $.post('/backend/security/bdTeam/update', {id: id, applyStatus: 0}, function (res) {
                    if (res.code < 0) {
                        layer.msg(res.message);
                    }
                    else {
                        layer.msg("审核通过");
                        tableIns.reload();
                    }
                }
            )
        }
    }

    layui.form.on('submit(promoteBtn)', function () {
        $.getJSON("/shopback/security/bdTeam/getQRcode", function (res) {
            if (res.code < 0) {
                layer.msg(res.message);
            }
            else {
                window.open(res.body, "newwindow", "height=800, width=800, top =100, left=500, toolbar=no, menubar=no, scrollbars =no, location=no");
            }
        })
        return false;
    });

    layui.form.on('submit(addBtn)', function () {
        openDialog({
            url: "/backend/security/bdTeam/detail",
            area: ["60%", "85%"]
        });
        return false;
    });


    layui.form.on('submit(searchBtn)', function (data) {
        tableIns.reload({
            where: data.field
        });
        return false;
    });
</script>
<script type="text/html" id="statusTpl">
    {{#  if(d.status ===1){ }}
    <span style="color: #FF0000;">禁用</span>
    {{#  } else { }}
    <span style="color: green;">启用</span>
    {{#  } }}
</script>
<script type="text/html" id="applyStatusTpl">
    {{#  if(d.applyStatus ===1 && d.status===1){ }}
    <span style="color: #FF0000;">审核不通过</span>
    {{#  } else { }}
    <span style="color: green;">审核通过</span>
    {{#  } }}
</script>
<script type="text/html" id="opbar">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-xs" lay-event="codeForm">查看兑换券列表</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="change">变更启用状态</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="changeApply">变更审核状态</a>
</script>
</body>
</html>
